package com.minimalist.lindi.mapper;

import com.minimalist.common.entity.lindi.po.LindiContractTemplateFieldOption;
import com.minimalist.common.entity.lindi.vo.contracttemplatefieldoption.LindiContractTemplateFieldOptionQueryVO;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryChain;
import com.mybatisflex.core.query.QueryWrapper;

import java.util.List;

/**
 * 林地指标平台_合同模板字段选项表 映射层。
 *
 * @author 11987
 * @since 2025-05-31
 */
public interface LindiContractTemplateFieldOptionMapper extends BaseMapper<LindiContractTemplateFieldOption> {

    /**
     * 根据ID查询合同模板字段选项
     *
     * @param contractTemplateFieldOptionId 合同模板字段选项ID
     * @return 合同模板字段选项
     */
    default LindiContractTemplateFieldOption selectContractTemplateFieldOptionByContractTemplateFieldOptionId(Long contractTemplateFieldOptionId){
        return selectOneByQuery(QueryChain.create().eq(LindiContractTemplateFieldOption::getContractTemplateFieldOptionId, contractTemplateFieldOptionId));
    }

    /**
     * 分页查询合同模板字段选项列表
     *
     * @param queryVO 查询条件
     * @return 分页结果
     */
    default Page<LindiContractTemplateFieldOption> selectPageContractTemplateFieldOptionList(LindiContractTemplateFieldOptionQueryVO queryVO){
        return paginate(queryVO.getPageNum(), queryVO.getPageSize(),
                QueryWrapper.create()
                        .eq(LindiContractTemplateFieldOption::getContractTemplateFieldId, queryVO.getContractTemplateFieldId())
                        .like(LindiContractTemplateFieldOption::getOptionLabel, queryVO.getOptionLabel())
                        .like(LindiContractTemplateFieldOption::getOptionValue, queryVO.getOptionValue())
                        .orderBy(LindiContractTemplateFieldOption::getSortOrder, true)
                        .orderBy(LindiContractTemplateFieldOption::getCreateTime, false));
    }

    /**
     * 根据合同模板字段ID查询选项列表
     *
     * @param contractTemplateFieldId 合同模板字段ID
     * @return 选项列表
     */
    default List<LindiContractTemplateFieldOption> selectContractTemplateFieldOptionListByContractTemplateFieldId(Long contractTemplateFieldId){
        return selectListByQuery(QueryChain.create()
                .eq(LindiContractTemplateFieldOption::getContractTemplateFieldId, contractTemplateFieldId)
                .orderBy(LindiContractTemplateFieldOption::getSortOrder, true)
                .orderBy(LindiContractTemplateFieldOption::getCreateTime, false));
    }
}
